package daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import dao.BackWelcomeDao;

import pojo.StaData;
import utils.DruidUtils;


public class BackWelcomeDaoImpl implements BackWelcomeDao{

	@Override
	public StaData getStaData() {
		Connection conn1 = DruidUtils.getConnection();
		Connection conn2 = DruidUtils.getConnection();
		Connection conn3 = DruidUtils.getConnection();
		Connection conn4 = DruidUtils.getConnection();
		Connection conn5 = DruidUtils.getConnection();
		Connection conn6 = DruidUtils.getConnection();
		Connection conn7 = DruidUtils.getConnection();
		//String sql1 = "select count(*) as sCount from resourceinfo where userId = ?";
		//String sql2 = "select sum(rsFavors) as fCount from (select * from resourceinfo where userId = ?) as temp";
		//String sql3 = "select count(*) as cCount from commentinfo where userId = ?";
		String sql1 = "select count(*) as cNum from college";
		String sql2 = "select count(*) as qNum from question";
		String sql3 = "select count(*) as aNum from answer";
		String sql4 = "select count(*) as artNum from article";
		String sql5 = "select count(*) as rNum from resource";
		String sql6 = "select count(*) as bNum from books";
		String sql7 = "select count(*) as mNum from message";
		StaData sd = new StaData();
		int cNum = 0;
		int qNum = 0;
		int aNum = 0;
		int artNum = 0;
		int rNum = 0;
		int bNum = 0;
		int mNum = 0;
		try {
			PreparedStatement pre1 = conn1.prepareStatement(sql1);
			ResultSet res1 = pre1.executeQuery();
			while(res1.next()) {
				cNum = res1.getInt("cNum");
			}
			sd.setcNum(cNum);
			
			PreparedStatement pre2 = conn2.prepareStatement(sql2);
			ResultSet res2 = pre2.executeQuery();
			while(res2.next()) {
				qNum = res2.getInt("qNum");
			}
			sd.setqNum(qNum);
			
			PreparedStatement pre3 = conn3.prepareStatement(sql3);
			ResultSet res3 = pre3.executeQuery();
			while(res3.next()) {
				aNum = res3.getInt("aNum");
			}
			sd.setaNum(aNum);
			
			PreparedStatement pre4 = conn4.prepareStatement(sql4);
			ResultSet res4 = pre4.executeQuery();
			while(res4.next()) {
				artNum = res4.getInt("artNum");
			}
			sd.setArtNum(artNum);
			
			PreparedStatement pre5 = conn5.prepareStatement(sql5);
			ResultSet res5 = pre5.executeQuery();
			while(res5.next()) {
				rNum = res5.getInt("rNum");
			}
			sd.setrNum(rNum);
			
			PreparedStatement pre6 = conn6.prepareStatement(sql6);
			ResultSet res6 = pre6.executeQuery();
			while(res6.next()) {
				bNum = res6.getInt("bNum");
			}
			sd.setbNum(bNum);
			
			PreparedStatement pre7 = conn6.prepareStatement(sql7);
			ResultSet res7 = pre7.executeQuery();
			while(res7.next()) {
				mNum = res7.getInt("mNum");
			}
			sd.setmNum(mNum);

			res1.close();
			pre1.close();
			conn1.close();
			res2.close();
			pre2.close();
			conn2.close();
			res3.close();
			pre3.close();
			conn3.close();
			res4.close();
			pre4.close();
			conn4.close();
			res5.close();
			pre5.close();
			conn5.close();
			res6.close();
			pre6.close();
			conn6.close();
			res7.close();
			pre7.close();
			conn7.close();
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return sd;
	}

}
